<template>
<!-- 注册证新增编辑弹框 -->
    <basic-modal :modalOpt="modal"  :footer="null" @closeModal="closeModal">
      <template>
        <a-steps class="steps" :current="current">
          <a-step v-for="item in steps" :key="item.title" :title="item.title" />
        </a-steps>
        <div class="steps-content"  v-show="current==0">
          <step1 @nextStep="nextStep" :orRrecord="orRrecord" ></step1>
        </div>
        <div class="steps-content"  v-show="current==1">
          <step2 :orRrecord="orRrecord" @onSubmit="onSubmit" @onCancel="previous"  :orderData="orderData"></step2>
        </div>
        
      </template>
    </basic-modal>
</template>

<script>
import basicModal from '../common/basicModal'
import basicForm from '../common/basicForm'
import step1 from './step1.vue'
import step2 from './step2.vue'
import {deleteInfo } from './saleDelivery'

export default {
  components: {
    basicModal,
    basicForm,
    step1,
    step2,
  },
  data() {
    return {
      loading: false,
      modal: {
        modalVisible: false,
        modalTitle: '填写配送单',
        modalWidth: '90vw',
      },
      current: 0,
      isNew:true,
      steps: [
        {
          title: '配送单基本信息',
          isSubmit: false,
        },
        {
          title: '配送单明细',
          isSubmit: false,
        },
      ],
      orderData:{},
      orRrecord:{}
      

    }
  },
  computed: {},
  mounted() {
    console.log(this.current);
  },
  methods: {
    // 新增按钮 点击了新增
    addModal(pid,record) {
      this.orRrecord=record
      this.isNew=true
      this.modal.modalVisible = true
      this.modal.modalTitle = '填写配送单'
    },
    // 点击了编辑
    editModal(current) {
      this.current=current
      this.isNew=false
      this.modal.modalVisible = true
      this.modal.modalTitle = '修改配送单'
    },
    nextStep(orderData){
      this.orderData=orderData
      this.current++
    },
    previous(){
      this.current--
    },
    onSubmit(){
      this.closeModal2()
    },
    unSubmit(){//中途关闭，此处添加删除未上传完的证照信息
      console.log('中途关闭，此处添加删除未上传完的证照信息',this.orderData.pid);
      if(this.orderData.pid){
        this.deleteInfo()
      }else{
        this.$message.warning({ content: '信息填写未完成', duration: 3 })
      }
    },
    closeModal() {
      this.unSubmit()
      this.modal.modalVisible = false
      this.current=0
      this.orderData={}
      this.$emit('close')
    },
    // 保存成功关闭模态详细框
    closeModal2() {
      this.modal.modalVisible = false
      this.current=0
      this.orderData={}
      this.$emit('ok')
    },
    async deleteInfo(val) {
      // this.$message.loading({ content: '提交中'， })
      let res = await deleteInfo(this.orderData)
      console.log(res)
      if (res && res.code && res.code === 'C1' && res.data) {
        this.$message.warning({ content: '信息填写未完成', duration: 3 })
        console.log("删除成功");
      }
    },
    
  },
}
</script>

<style scoped>
.steps-content{
  padding-top:10px;
  width: 100%;
  height: calc( 80vh - 40px );

}
.steps{
  width: 80%;
  margin: 0 auto;
}
</style>